home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UErrorMgr.cp < prev    next >
Encoding:
Text File  |  1991-05-01  |  6.4 KB  |  284 lines  |  [TEXT/MPS ]

  1. // UErrorMgr.cp 
  2. // Copyright © 1984-1991 by Apple Computer Inc. All rights reserved.
  3.  
  4.  
  5. #ifndef __UERRORMGR__
  6. #include <UErrorMgr.h>
  7. #endif
  8.  
  9. #ifndef __STDIO__
  10. #include <StdIo.h>
  11. #endif
  12.  
  13. #ifndef __TOOLUTILS__
  14. #include <ToolUtils.h>
  15. #endif
  16.  
  17. #ifndef __RESOURCES__
  18. #include <Resources.h>
  19. #endif
  20.  
  21. #ifndef __UFAILURE__
  22. #include <UFailure.h>
  23. #endif
  24.  
  25. #ifndef __UMACAPPUTILITIES__
  26. #include <UMacAppUtilities.h>
  27. #endif
  28.  
  29. #ifndef __UMENUMGR__
  30. #include <UMenuMgr.h>
  31. #endif
  32.  
  33. #ifndef __MEMORY__
  34. #include <Memory.h>
  35. #endif
  36.  
  37. //--------------------------------------------------------------------------------------------------
  38. Str255 gErrorParm3;
  39. ProcPtr gMacAppAlertFilter;
  40. Boolean gInFilter;
  41. Boolean gInhibitNestedHandling;
  42.  
  43. //--------------------------------------------------------------------------------------------------
  44. struct ErrRecord
  45. {
  46.     short lowErr, highErr, index;
  47. };
  48.  
  49.  
  50. typedef ErrRecord* ErrRecordPointer;
  51. typedef ErrRecordPointer* ErrRecordHandle;
  52.  
  53. //--------------------------------------------------------------------------------------------------
  54. #pragma segment MAError
  55.  
  56. pascal void ErrorAlert(OSErr err,
  57.                        long message)
  58. {
  59.     union Converter
  60.     {
  61.         struct
  62.         {
  63.             short hiWd, loWd;
  64.         } shortVal;
  65.         long message;
  66.     };
  67.  
  68.  
  69.     const long kMsgCmdErr = msgCmdErr / 0x10000;
  70.     const long kMsgAlert = msgAlert / 0x10000;
  71.     const long kMsgLookup = msgLookup / 0x10000;
  72.     const long kMsgAltRecov = msgAltRecovery / 0x10000;
  73.  
  74.     Converter c;
  75.     short alertID = phGenError;                    // the default alert
  76.     Boolean genericAlert = TRUE;
  77.     Str255 opString = "";
  78.     Str255 errStr;
  79.     OSErr recovErr;
  80.     Str255 recovery;
  81.  
  82.     c.message = message;
  83.  
  84.     switch (c.shortVal.hiWd)
  85.     {
  86.         case kMsgCmdErr:
  87.             alertID = phCmdErr;
  88.             CmdToName(c.shortVal.loWd, opString);
  89.             break;
  90.  
  91.         case kMsgAlert:
  92.             alertID = c.shortVal.loWd;
  93.             genericAlert = FALSE;
  94.             break;
  95.  
  96.         case kMsgLookup:
  97.         case kMsgAltRecov:
  98.             LookupErrString(c.shortVal.loWd, errOperationsID, opString);
  99.             break;
  100.  
  101.         default:
  102.             GetIndString(opString, c.shortVal.hiWd, c.shortVal.loWd);
  103.             break;
  104.     }
  105.  
  106.     if (genericAlert)
  107.     {
  108.         LookupErrString(err, errReasonID, errStr);
  109.  
  110.         if (c.shortVal.hiWd == kMsgAltRecov)
  111.             recovErr = c.shortVal.loWd;
  112.         else
  113.             recovErr = err;
  114.  
  115.         LookupErrString(recovErr, errRecoveryID, recovery);
  116.  
  117.         ParamText(errStr, recovery, opString, gErrorParm3);
  118.  
  119.         if (opString.IsEmpty())
  120.             alertID = phUnknownErr;
  121.     }
  122.  
  123.     StdAlert(alertID);
  124.     gInhibitNestedHandling = FALSE;                // Used suppress nested event handling 
  125.  
  126.     if (genericAlert)
  127.         ResetAlrtStage();
  128. }
  129.  
  130. //--------------------------------------------------------------------------------------------------
  131. #pragma segment MAError
  132.  
  133. // Private function
  134. pascal Boolean SearchErrTable(short value,
  135.                               short resourceID,
  136.                               Str255& str)
  137. {
  138.     ErrRecordHandle table;
  139.  
  140.     str = "";
  141.     table = (ErrRecordHandle)GetResource('errs', resourceID);
  142.     if (table)
  143.     {
  144.         short lenTab;
  145.         short strID = 0;
  146.         ErrRecordPointer pEntry = *table;
  147.  
  148.         lenTab = (short)(GetHandleSize((Handle)table) / sizeof(ErrRecord));
  149.         for (short i = 1; i <= lenTab; ++i, ++pEntry)
  150.         {
  151.             if (pEntry->lowErr == 0)
  152.                 strID = pEntry->index;
  153.             else if ((pEntry->lowErr <= value) && (value <= pEntry->highErr))
  154.             {
  155.                 if (pEntry->index > 0)
  156.                     GetIndString(str, strID, pEntry->index);
  157.                 return TRUE;
  158.             }
  159.         }
  160.     }
  161.     return FALSE;
  162. }
  163.  
  164.  
  165. pascal Boolean LookupErrString(short value,
  166.                                short resourceID,
  167.                                Str255& str)
  168. {
  169.     if (SearchErrTable(value, errAppTable + resourceID, str))
  170.         return TRUE;
  171.     else
  172.         return SearchErrTable(value, resourceID, str);
  173. }
  174.  
  175. //--------------------------------------------------------------------------------------------------
  176. /*$MC68020-*/                                    /* Need to be able to alert user if this
  177.                                                   isn't a 68020 machine */
  178. #pragma segment MAGlobalsRes
  179. // Don't require a segment load for this 
  180.  
  181. pascal void StdAlert(short alertID)
  182. {
  183.     MacAppAlert(alertID, NULL);
  184. }
  185.  
  186. //--------------------------------------------------------------------------------------------------
  187. /*$MC68020-*/                                    /* Need to be able to alert user if this
  188.                                                   isn't a 68020 machine, alert filter won't
  189.                                                   be installed until after that, though. */
  190. #pragma segment MAGlobalsRes
  191. // Don't require a segment load for this 
  192.  
  193. pascal short MacAppAlert(short alertID,
  194.                          ProcPtr filterProc)
  195. {
  196.     AlertTHndl alrtTemplate;
  197.     Boolean canAlert;
  198.     SignedByte savedState;
  199.     short alertReturn;
  200.  
  201. #if qDebug
  202.     gRsrcCheck = 0;                                // force immediate check. 
  203. #endif
  204.  
  205.     SetCursor(qd.arrow);
  206.     alrtTemplate = (AlertTHndl)GetResource('ALRT', alertID);
  207.     if (!alrtTemplate)
  208.     {
  209. #if qDebug
  210.         Str255 theString;
  211.         ConcatNumber("Unable to find or load ‘ALRT’ resource ", alertID, theString);
  212.         ProgramBreak(theString);
  213. #endif
  214.  
  215.         SysBeep(2);                                // At least give some indication 
  216.         return 1;                                // Arbitrary result 
  217.     }
  218.  
  219.     if (!GetResource('DITL', (*alrtTemplate)->itemsID))// preflight the DITL 
  220.     {
  221. #if qDebug
  222.         Str255 theString;
  223.         ConcatNumber("Unable to find or load ‘DITL’ resource ", alertID, theString);
  224.         ProgramBreak(theString);
  225. #endif
  226.  
  227.         SysBeep(2);                                // At least give some indication 
  228.         return 1;                                // Arbitrary result 
  229.     }
  230.  
  231.     CouldAlert(alertID);
  232.     canAlert = (ResError() == noErr) && (MemError() == noErr);
  233.     FreeAlert(alertID);
  234.     if (!canAlert)
  235.     {
  236. #if qDebug
  237.         Str255 theString;
  238.         ConcatNumber("Unable to display alert ", alertID, theString);
  239.         ProgramBreak(theString);
  240. #endif
  241.  
  242.         SysBeep(2);                                // At least give some indication 
  243.         return 1;                                // Arbitrary result 
  244.     }
  245.  
  246.     // Success at last!
  247.     savedState = LockHandleHigh((Handle)alrtTemplate);
  248.  
  249.     // Only center the ALRT if not on System 7, otherwise assume that the bit is set
  250.     // in the ALRT template in order to do the centering.
  251.     if (!(qNeedsSystem7 || gConfiguration.systemVersion >= 0x700))
  252.         CenterRectOnScreen((*alrtTemplate)->boundsRect, TRUE, TRUE, TRUE);
  253.  
  254.     PullApplicationToFront();    // !!! hmmm...do we need this on System 7
  255.  
  256.     if (!filterProc)
  257.         alertReturn = Alert(alertID, (ModalFilterProcPtr)gMacAppAlertFilter);
  258.     else
  259.         alertReturn = Alert(alertID, (ModalFilterProcPtr)filterProc);
  260.  
  261.     // restore the state of the DITL's handle
  262.     HSetState((Handle)alrtTemplate, savedState);
  263.     return alertReturn;
  264. }
  265.  
  266. //--------------------------------------------------------------------------------------------------
  267. #pragma segment MAError
  268.  
  269. #if qDebug
  270. pascal void NotYetImplemented(const Str255& where)
  271. #else
  272. pascal void NotYetImplemented(const Str255&        /* where */)
  273. #endif
  274.  
  275. {
  276. #if qDebugMsg
  277.     fprintf(stderr, "NotYetImplemented: %s\n", (char *) where);
  278. #endif
  279.  
  280.     Failure(errNotImplemented, 0);
  281. }
  282.  
  283.  
  284.